home *** CD-ROM | disk | FTP | other *** search
Wrap
<HTML> <HEAD> <SCRIPT language="JavaScript"> <!-- Begin var subtitle = "EasyCounter"; var title = "Cool Page " + subtitle; var requires_cool_page = "This file is only useful when used as designed in conjunction with Cool Page."; var requires_coolpage_update = "To edit this object, please upgrade your copy of Cool Page to the latest version."; var publisher_url = "http://www.coolpage.com"; var unexpected_error = 'An unexpected error occurred. Please notify publisher of this "' + title + '" plugin at ' + publisher_url; var objects_folder_name = "Objects"; var objects_subfolder = "Counter"; // Cool Page Objects subfolder which contains any folder(s) which contain this file var num_digits = 10; var unsupported_image_type = "Only JPEG (JPG), GIF, and PNG image files are supported.\r\nPlease select a different file."; var apply_first = "To customize the counter digits images, click Browse then Apply."; var browse_first = "Click Browse before Apply.\r\nApply the change after browsing for the new file."; var cgi_file = "EasyCounter.cgi"; var is_http = (window.location.protocol.indexOf( "http" ) == 0); document.write( "<TITLE>" + title + "</TITLE>" ); function AlertClose( msg ) { alert( msg ); document.write( "</HEAD><BODY></BODY></HTML>" ); document.close(); } // Is Cool Page API not available thru the DOM? var undefined, defined; if( !window.external || !window.external.Undefined || !window.external.Defined || (undefined = window.external.Undefined()) == (defined = window.external.Defined()) ) { AlertClose( requires_cool_page ); } // Inputs Cool Page API return value, alerts if unexpected error occurred, and returns 'undefined' value if unsuccessful function ChkErr( line, return_value ) { if( return_value == "" || return_value == undefined ) { alert( line ); AlertClose( unexpected_error ); return undefined; } return return_value; } // No HTML has been set yet for this object, so we are initializing it for 1st time? if( window.external.GetObjectHTML( "-1" ) == defined ) { // Do any initialization of the Cool Page PageHTML object here // To avoid possible errors with zero or negative size objects, initialize // at least the width to some positive values here ChkErr( 54, window.external.SetObjectSize( "-1", "1", "1" ) ); } // Not all APIs used by this file are available? var w, h; if( !window.external.GetSelectedObject || window.external.GetSelectedObject( "-1" ) == undefined || !window.external.GetObjectClass || window.external.GetObjectClass( "-1" ) != "PageHTML" || !window.external.GetObjectEditor || window.external.GetObjectEditor( "-1" ) == undefined || !window.external.SetObjectEditorName || window.external.SetObjectEditorName( "-1" , title ) == undefined || !window.external.GetObjectWidth || (w = window.external.GetObjectWidth( "-1")) == undefined || !window.external.GetObjectHeight || (h = window.external.GetObjectHeight( "-1" )) == undefined || !window.external.SetObjectSize || window.external.SetObjectSize( "-1", w, h ) == undefined || !window.external.GetObjectHTML || (h = window.external.GetObjectHTML( "-1" )) == undefined || !window.external.SetObjectHTML || window.external.SetObjectHTML( "-1", (h == defined ? "" : h) ) == undefined || !window.external.GetObjectFiles || window.external.GetObjectFiles( "-1", ";" ) == undefined || !window.external.SetObjectFiles // unrealistic to check all argument variants here just assume they are supported || window.external.SetObjectFiles( "-1", file0, file1, ... fileN ) == undefined || !window.external.CopyFile || window.external.CopyFile( "", "" ) == undefined || !window.external.GetFilesList || window.external.GetFilesList( "", "" ) == undefined ) { AlertClose( requires_coolpage_update ); } // Find the Objects folder by assuming that this file is the Editor and permanently resides in Object folder hierarchy var editor = ChkErr( 78, window.external.GetObjectEditor( "-1" ) ); var i = editor.lastIndexOf( "\\" + objects_folder_name + "\\" + objects_subfolder ); if( i < 0 ) { AlertClose( unexpected_error ); } var objects_folder = editor.substring( 0, i + objects_folder_name.length + 2 ); var digits_folder = objects_folder + "Text\\EasyCounter Digits\\"; // Extract temporary folder of this page on hard disk, from the browser encoded url // Cool Page API copies this file from it's permanent folder to a temporary folder while in use var prefix = "file:///"; var url = window.location.href; if( url.indexOf( prefix ) != 0 ) { alert( unexpected_error ); } var temp_folder = url.substring( prefix.length, url.lastIndexOf( "/" ) ).replace( /%20/g, " " ).replace( /\//g, "\\" ); // Parse list of styles and file types from digit images full (0 - 9) sets // in the EasyCounter Digits folder of Cool Page Objects window. // If input 'mode' == "options" then a list of <OPTION value="file type">style</OPTION> is written to output // Else Array( "style", "ext" ) is returned for the first found, or "" values if none found. function ParseDigitsFolder( mode ) { var first_found = new Array( "style", "ext" ); var folder = digits_folder.substring( 0, digits_folder.length - 1 ); var file_array = window.external.GetFilesList( folder, "|", "" ).split( "|" ); if( file_array[0] != "" && file_array[0] != defined ) { for( var i = file_array.length; --i >= 0; ) { var file = file_array[i]; if( file ) { var t = file.lastIndexOf( "." ); var ext = file.substring( t + 1 ); var style = file.substring( file.lastIndexOf( digits_folder ) + digits_folder.length, t - 1 ); var j = 9; for( var k = i + 1; --k >= 0; ) { var s = file_array[k]; if( s == digits_folder + style + j + "." + ext ) { if( --j >= 0 ) { file_array[k] = 0; // Mark in list that file is used for a Style k = i + 1; } else if( mode == "options" ) { document.writeln( '<OPTION value="' + ext + '">' + style + '</OPTION>' ); break; } else { first_found["style"] = style; first_found["ext"] = ext; return first_found; } } } } } } return first_found; } // Return the current values of the selected Cool Page PageHTML object, // or return the default values if the HTML == "" for the object function ParseHTML() { var current = new Array( "width", "height", "digit_images", "preview_count" ); current["width"] = ChkErr( 155, window.external.GetObjectWidth( "-1" ) ); current["height"] = ChkErr( 156, window.external.GetObjectHeight( "-1" ) ); // Initialize any files which get uploaded with the web page for the Cool Page PageHTML object current["digit_images"] = new Array( num_digits ); // Read (parse) any current files for the Cool Page PageHTML object var file_array = ChkErr( 162, window.external.GetObjectFiles( "-1", "|" ) ).split( "|" ); if( file_array[0] != defined && file_array.length == num_digits ) { for( var i = num_digits; --i >= 0; ) { current["digit_images"][i] = file_array[i]; } } else { if( file_array[0] != defined && file_array.length != num_digits ) { alert( unexpected_error ); } // Initialize instead var default_digits = ParseDigitsFolder( 0 ); for( var i = num_digits; --i >= 0; ) { current["digit_images"][i] = digits_folder + default_digits["style"] + i + "." + default_digits["ext"]; } } // Initialize any variables which are persistant in the HTML for the Cool Page PageHTML object current["preview_count"] = '9876543210'; // Read (parse) any variables which are persistant in the HTML for the Cool Page PageHTML object var html = ChkErr( 189, window.external.GetObjectHTML("-1") ); if( html == defined ) return current; var s = 'var easy_counter_count = '; var i = html.indexOf( s ); if( i < 0 ) { alert( unexpected_error ); } else { var s = html.substring( i + s.length ); i = s.indexOf( ';' ); if( i < 0 ) { alert( unexpected_error ); } else { current["preview_count"] = s.substring( 0, i ); } } return current; } function Max( a, b ) { return a > b ? a : b; } // Return index, within <OPTIONS> of input <SELECT>, of counter Style chosen, // based on the current digit images of the <FORM> that contains the <SELECT> function ReadStyleIndex( select ) { var file = select.form.digit0.value; var t = file.lastIndexOf( "." ); var ext = file.substring( t + 1 ); var style = file.substring( file.lastIndexOf( digits_folder ) + digits_folder.length, t - 1 ); for( var i = num_digits; --i >= 0; ) { eval( 'var s = select.form.digit' + i + '.value;' ); if( s != digits_folder + style + i + "." + ext ) { break; } } // Search for index of style (all digit images same style)? if( i < 0 ) { for( var i = select.length; --i >= 0; ) { if( select.options[i].text == style && select.options[i].value == ext ) { return i; } } } // Return index of "Customize" style return select.length - 1; } // Read the values of the currently selected Cool Page PageHTML object, // and set the values for the GUI <FORM> in this file function ReadSelectedObject( form ) { var current = ParseHTML(); /////////////////////// // Write parsed values into the <FORM> for( var i = num_digits; --i >= 0; ) { eval( 'form.digit' + i + '.value = current["digit_images"][i];' ); } var i = ReadStyleIndex( form.cstyle ); form.cstyle.selectedIndex = i; form.cstyle.options[i].selected = true; form.count.value = current["preview_count"]; /////////////////////// // Copy any images displayed or files used in this file to the current temporary folder // The Cool Page API will delete these temporary files when no longer in use // Note these are files which MUST be in the same folder as this file, // when the embedded browser is displaying this file // Copy any files from where this page normally resides (this file is the 'editor') // to the temporary folder where this file is currently being browsed from /* This file currently uses no such files but code kept here for example var applet = editor.substring( 0, editor.lastIndexOf( "\\" ) + 1 ) + applet_file; ChkErr( 285, window.external.CopyFile( applet, temp_folder ) ); */ // Copy any files from where they are to the temporary folder where this file is currently being browsed from for( var i = num_digits; --i >= 0; ) { eval( 'window.external.CopyFile( form.digit' + i + '.value, temp_folder );' ); } } // Return Array( "width", "height", "sizes" ) based on the size of the digit images, // where sizes is an Array( 'num_digits' ) of Array( "width", "height" ). function CalcSize( form ) { // Copy any files from where they are to the temporary folder where this file is currently being browsed from for( var i = num_digits; --i >= 0; ) { eval( 'window.external.CopyFile( form.digit' + i + '.value, temp_folder );' ); } var t = new Array( "width", "height", "sizes" ); t["sizes"] = new Array( num_digits ); var w = 0, h = 0; for( var i = num_digits; --i >= 0; ) { eval( 'var s = form.digit' + i + '.value ;' ); var img = new Image(); img.src = s.substring( s.lastIndexOf( "\\" ) + 1 ); // Width and height of image not loaded yet? if( !img.width || !img.height ) { // Use a complex loop not optimized by browser to give time for browser cache to load the image i++; continue; } t["sizes"][i] = new Array( "width", "height" ); t["sizes"][i]["width"] = img.width; t["sizes"][i]["height"] = img.height; w = Max( img.width, w ); h = Max( img.height, h ); } // Allocate enough width for maximum of 1 billion (10 digits) counter hits, or preview count length, plus a fudge factor of 1 digit var cnt = new String( form.count.value ); t["width"] = w * (Max( 10, cnt.length ) + 1); t["height"] = h; return t; } // Write the values for the GUI <FORM> in this file, into the values of the currently Cool Page PageHTML object // Returns true if successful function WriteSelectedObject( form ) { // If any required values are empty, then assume the <FORM> is in a transistional state (this function called // from event trigger) and thus return without doing any thing for( var i = num_digits; --i >= 0; ) { eval( 'var t = form.digit' + i + '.value;' ); if( t == "" ) { return false; } } // Read the current values of the Cool Page PageHTML object var current = ParseHTML(); // Get the width and height from the size of the digit images var size = CalcSize( form ); // If not possible to set needed width and height, the assume Cool Page has warned the user // and just return without setting the rest of current values if(!ChkErr( 359, window.external.SetObjectSize( "-1", size["width"].toString(), size["height"].toString() ) ) ) return false; // Derive from the <FORM>, the HTML for the selected Cool Page PageHTML var html = DerivedHTML( form ); // Set the list of files to empty before setting HTML, because Cool Page warns user if // any files in list are not referenced in the HTML. ChkErr( 367, window.external.SetObjectFiles( "-1" ) ); ChkErr( 368, window.external.SetObjectHTML( "-1", html ) ); // Set list of files referenced by the HTML var command = 'ChkErr( 371, window.external.SetObjectFiles( "-1"'; for( var i = 0; i < num_digits; i++ ) { eval( 'var file = form.digit' + i + '.value;' ); if( file != "" ) command += ', form.digit' + i + '.value'; } eval( command + ' ) );' ); // If any value has changed, then reload this file (web page) so that any preview of the // DerivedHTML() on this web page is updated if( form.count.value != current["preview_count"] ) { window.location.reload( true ); } for( var i = num_digits; --i >= 0; ) { eval( 'if( form.digit' + i + '.value != current["digit_images"][i] ) { window.location.reload( true ); }' ); } return true; } // Derive the HTML for the selected Cool Page PageHTML object from the value of the <FORM> function DerivedHTML( form ) { var cr = '\r\n'; var html = '<' + '!-- Begin Cool Page : EasyCounter(tm) --' + '>' +cr // Default counter value + '<' + 'SCRIPT language="JavaScript"' + '>' +cr + '<' + '!--' +cr + 'var easy_counter_count = ' + form.count.value + ';' +cr + 'var easy_counter_supported = 0;' +cr + '//--' + '>' +cr + '<' + '/SCRIPT' + '>' +cr; // Call the Host cgi script to return the EasyCounterCount() value html += '<' + 'SCRIPT language="php"' + '>' +cr + '//<' + '!--' +cr + 'if( !function_exists( "file_exists2" ) )' +cr + '{' +cr + ' function file_exists2( $f, $paths, $delimiter )' +cr + ' {' +cr + ' $d = explode( $delimiter, $paths );' +cr + ' while( (list( $k, $path ) = each( $d )) != 0 )' +cr + ' {' +cr + ' if( file_exists( $path . "/" . $f ) )' +cr + ' return true;' +cr + ' }' +cr + ' return false;' +cr + ' }' +cr + '}' +cr +cr + '$file = "EasyCounter.php";' +cr + 'if( file_exists( $file ) || file_exists2( $file, ini_get( "include_path" ), ":" ) )' +cr + '{' +cr + ' include $file;' +cr + ' if( function_exists( "EasyCounterCount" ) )' +cr + ' {' +cr + ' echo "<", "SCRIPT language=\\"JavaScript\\">\\n";' +cr + ' echo "<", "!--\\n";' +cr + ' echo "easy_counter_count = ", EasyCounterCount(), ";\\n";' +cr + ' echo "easy_counter_supported = 1;\\n";' +cr + ' echo "//--", ">\\n";' +cr + ' echo "<", "/SCRIPT", ">\\n";' +cr + ' }' +cr + '}' +cr + '//--' + '>' +cr + '<' + '/SCRIPT' + '>' +cr; // Output the digit images html += '<' + 'SCRIPT language="JavaScript"' + '>' +cr + '<!--' +cr + 'var digits = new Array( ' + num_digits + ' );' +cr + 'for( var i = ' + num_digits + '; --i >= 0; ) { digits[i] = new Array( "file", "width", "height" ); }' +cr; var sizes = CalcSize( form )["sizes"]; for( var i = num_digits; --i >= 0; ) { eval( 'var f = form.digit' + i + '.value;' ); f = f.substring( f.lastIndexOf( '\\' ) + 1 ); html += 'digits[' + i + ']["file"] = "' + f + '";' +cr; html += 'digits[' + i + ']["width"] = ' + sizes[i]["width"] + ';' +cr; html += 'digits[' + i + ']["height"] = ' + sizes[i]["height"] + ';' +cr; } html += 'var cnt = new String( easy_counter_count );' +cr + 'var alt = (easy_counter_supported ? cnt : (is_http ? "EasyCounter not supported on this Host" : "Preview value for EasyCounter"));' +cr + 'for( var i = 0; i < cnt.length; i++ )' +cr + '{' +cr + ' var j = cnt.charAt(i);' +cr + " document.write( '<' + 'IMG SRC=\"' + digits[j]['file'] + '\" ALT=\"' + alt + '\" WIDTH=' + digits[j]['width'] + ' HEIGHT=' + digits[j]['height'] + ' BORDER=0 HSPACE=0 VSPACE=0' + '>' );" +cr + '}' +cr + "document.writeln( '<' + 'BR' + '>' );" +cr // fix last line spacing with small font bug + '//--' + '>' +cr + '<' + '/SCRIPT' + '>' +cr // If no JavaScript, then output text preview count + '<' + 'NOSCRIPT' + '>' + form.count.value + '<' + '/NOSCRIPT' + '>' +cr + '<' + '!-- End Cool Page : EasyCounter(tm) --' + '>' +cr; return html; } // Process change events on the Style <SELECT> of GUI <FORM> function OnStyleChange( select ) { var style = select.options[select.selectedIndex].text; var ext = select.options[select.selectedIndex].value; // Style != "Customize" so set the digit images for the selected style? if( ext != "" ) { for( var i = num_digits; --i >= 0; ) { eval( 'select.form.digit' + i + '.value = digits_folder + style + i + "." + ext;' ); } } else { alert( apply_first ); } WriteSelectedObject( select.form ); } // Process onMouseDown events on the Apply button for Digit Images of GUI <FORM> function OnApplyNewImage( form, index ) { eval( 'var t = form.newdigit' + index + '.value;' ); // Insure user Browses before Apply eval( 'form.newdigit' + index + '.value = "";' ); if( t == "" ) { alert( browse_first ); return; } var ext = t.substring( t.lastIndexOf( "." ) + 1 ).toLowerCase(); if( ext == "jpg" || ext == "gif" || ext == "jfi" || ext == "jpeg" || ext == "png" ) { // Before setting new image, insure that Style = "Customize" form.cstyle.selectedIndex = form.cstyle.length - 1; eval( 'form.digit' + index + '.value = t;' ); WriteSelectedObject( form ); } else { alert( unsupported_image_type ); } } // End --> </SCRIPT> <STYLE type="text/css">P, TD {font:normal 10pt Arial, sans-serif; color:#000000}</STYLE> </HEAD> <!-- Begin <BODY> of GUI that will appear embedded in Cool Page for editing the selected PageHTML --> <BODY SCROLL="auto" BGCOLOR="#d0ccc4"> <SCRIPT language="JavaScript"> <!-- Begin var tm = '<' + 'SUP' + '><' + 'SMALL' + '>TM<' + '/SMALL' + '><' + '/SUP' + '>'; document.writeln( '<' + 'CENTER' + '><' + 'H2' + '>' + title + tm + '<' + '/H2' + '>' ); document.writeln( '<' + 'H3' + '>Easiest, fastest, most customizable counter.<' + '/H3' + '><' + '/CENTER' + '>' ); document.writeln( '<' + 'P' + '>This counter <' + 'B' + '>ONLY<' + '/B' + '> works on ' + subtitle + tm + ' compatible Hosts.<' + 'BR' + '>' ); document.writeln( 'When Publishing, set Host = "Cool Page", Host = "EzHoster", or visit the ' ); document.writeln( '<' + 'A HREF="http://coolpagehelp.com/easycounter.html" TARGET="_new"' + '><' + 'B>Counters<' + '/B' + '><' + '/A> guide at <' + 'A HREF="http://coolpagehelp.com" TARGET="_new"' + '><' + 'B>CoolPageHelp.com<' + '/B' + '><' + '/A' + '> for list of ' + subtitle + tm + ' compatible Hosts.<' + 'BR' + '><' + '/P' + '>' ); // End --> </SCRIPT> <FORM name="editor" action=""> <P align="center">Style: <SELECT name="cstyle" onChange="javascript:OnStyleChange( this );"> <SCRIPT language="JavaScript"> <!-- Begin // Write list of <OPTION> styles from digit images full (0 - 9) sets in the EasyCounter Digits folder // of Cool Page Objects window ParseDigitsFolder( "options" ); // End --> </SCRIPT> <OPTION value="">Customize</OPTION> </SELECT> </P> <P>Choose a Style above, or choose any image you want to use for the counter digits below:</P> <TABLE align="center"> <SCRIPT language="JavaScript"> <!-- Begin for( var i = 0; i < num_digits; i++ ) { document.writeln( '<' + 'TR' + '>' ); document.writeln( ' <' + 'TD' + '>Digit ' + i + ' Image:<' + '/TD' + '>' ); document.writeln( ' <' + 'TD' + '><' + 'INPUT type="text" size="50" name="digit' + i + '" onFocus="javascript:this.blur();"' + 'TITLE="File to use for digit ' + i + ' of counter">' ); document.writeln( ' <' + 'INPUT type="file" size="1" name="newdigit' + i + '"' + 'TITLE="Browse for a file to use for digit ' + i + ' of counter">' ); document.writeln( ' <' + 'INPUT type="button" value="Apply" onMouseDown="javascript:OnApplyNewImage( this.form, ' + i + ' );"' + 'TITLE="Apply the file chosen with Browse for digit ' + i + ' of counter">' ); document.writeln( ' <' + '/TD' + '>' ); document.writeln( '<' + '/TR' + '>' ); } // End --> </SCRIPT> </TABLE> <P align="center">Preview Count: <INPUT type="text" size="10" maxlength="10" name="count" onChange="javascript:this.value=this.value.replace( /[^0-9]/g, '' );WriteSelectedObject( this.form );" TITLE="Count displayed when web page is Previewed"> </P> </FORM> <SCRIPT language="JavaScript"> <!-- Begin ReadSelectedObject( document.editor ); document.writeln( '<' + 'P align="center"' + '>' + DerivedHTML( document.editor ) + '<' + '/P' + '>' ); // Make sure we set the default values in the PageHTML to initialize it when the PageHTML is first created, // e.g. dropped into the web page. This is done here instead of at top of this page, because we desire to // use WriteSelectedObject() which depends on the "document.editor" <FORM>. if( window.external.GetObjectHTML( "-1" ) == defined ) { WriteSelectedObject( document.editor ); } // End --> </SCRIPT> <P><B>Add Styles:</B> To add new Styles to this counter, simply add images for all 10 digits (0 - 9) to the "<I>EasyCounter Digits</I>" folder within the "<I>Text</I>" folder of the Objects window. Open the "<I>Text</I>" folder by clicking it's "+" sign in the left pane of the Objects window. All 10 digits of a Style much have the same file name, except for the number "0" - "9" appended. See the existing images in the "<I>EasyCounter Digits</I>" folder for examples. Visit the <A HREF="http://coolpagehelp.com/easycounter.html" TARGET="_new"><B>Counters</B></A> guide at <A HREF="http://coolpagehelp.com" TARGET="_new"><B>CoolPageHelp.com</B></A> for easy instructions for obtaining and adding more Styles to this counter.</P> <P><B>Technical Note:</B> This counter uses a super-fast innovative technology. Other counters typically load a dynamic image from the Host server. This counter retrieves only the numeric value from the server, then assembles the digit images on the client (in the browser). Thus the digit images are cached (by the browser and internet caches) resulting in faster page load times, and less Host resources used. Convince your Host to support this counter. Tell your Host to read the EasyCounter specification in the Extending Cool Page section of User Manual in Cool Page Help menu.</P> <P><B>Speed Note:</B> Like all other counters, this counter will be as fast as the speed of the Host script, and at non-cache times, as fast as the file size of the digit images can be loaded. The difference is that at cache times (usually most of the time), this counter will not have to wait to load the digit images.</P> </BODY> </HTML>